<template>
  <div>
    <detail-banner :sightName="sightName"
                   :bannerImg="bannerImg"
                   :bannerImgs="galleryImgs"></detail-banner>
    <detail-header></detail-header>
    <detail-list :list="list"></detail-list>
    <div class="content"></div>
  </div>
</template>
<script>
import DetailBanner from './components/Banner'
import DetailHeader from './components/Header'
import DetailList from './components/List'
import axios from 'axios'
export default {
  name: 'Detail',
  components: {
    DetailBanner,
    DetailHeader,
    DetailList
  },
  data () {
    return {
      axiosId: '',
      sightName: '',
      bannerImg: '',
      galleryImgs: [],
      list: []
    }
  },
  methods: {
    getDetailInfo () {
      axios.get('/api/detail.json', {
        params: {
          id: this.$route.params.id
        }
      }).then(this.getDetailInfoSucc)
    },
    getDetailInfoSucc (res) {
      res = res.data
      console.log(res)
      if (res.ret && res.data) {
        let data
        res.data.forEach(item => {
          if (item.id === this.$route.params.id) {
            data = item
          }
        })
        console.log(data)
        this.sightName = data.sightName
        this.bannerImg = data.bannerImg
        this.galleryImgs = data.gallaryImgs
        this.list = data.priceType
      }
    }
  },
  mounted () {
    this.axiosId = this.$route.params.id
    this.getDetailInfo()
  },
  activated () {
    if (this.axiosId !== this.$route.params.id) {
      this.getDetailInfo()
    }
  }
}
</script>
<style lang="stylus" scoped>
.content {
  height: 50rem;
}
</style>
